﻿package  
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	/**
	 * ...
	 * @author Tuan
	 */
	public class mcMainNews extends MovieClip
	{
		//Load file xml
		var request:URLRequest;
		var xml:XML;
		var loader:URLLoader;
		var news:mcNewsElement;
		var newsList:XMLList;
		
		public function mcMainNews() 
		{
			request = new URLRequest("news.xml");
			loader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, onComplete);
			loader.load(request);
		}
		
		public function onComplete(e:Event):void
		{
			if (e.currentTarget == loader)
			{
				xml = new XML(loader.data);
				newsList = new XMLList(xml.news);
				for (var i:int = 0; i < newsList.length(); i++)
				{
					xml = new XML(newsList[i]);
					news = new mcNewsElement(xml);
					this.addChild(news);
					news.x = 0;
					news.y = i * (news.height + 15);
				}
			}
		}
	}
}